//
//  MainViewController.swift
//  SinaWeibo
//
//  Created by Yuan on 16/4/7.
//  Copyright © 2016年 Yuan. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    @objc private func compsoeDidClick(){
        print("btn click")
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        
        //由于tabBar是只读，不能直接操作，如果要修改，可以使用kvc
        let mainTabBar = MainTabBar()
        
        setValue(mainTabBar, forKey: "tabBar")
        
        
        
        addChildViewControllers()
        
//        print(tabBar.classForCoder)
        
        mainTabBar.composeBtn.addTarget(self, action: "compsoeDidClick", forControlEvents: .TouchUpInside)
    }
    
    private func addChildViewControllers() {
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        
         addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        
         addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
        
        
    }

    private func addChildViewController(vc: UIViewController,title: String,imageName: String)
    {
       
        
        //self.tabBar.tintColor = UIColor.orangeColor()
        //实例化导航视图控制器
        
        let nav = UINavigationController(rootViewController: vc)
        
        //标题
        vc.title = title
        
        //图标
        vc.tabBarItem.image = UIImage(named: imageName)
        
//        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
        
        //添加
        addChildViewController(nav)
    }
    

 

}
